<?php
namespace App\Controllers;
use \interop\Container\ContainerInterface as ContainerInterface;
use App\Models\UserModel;
use App\Models\OperaModel;
use pdo;
class AnnounceController extends BaseController{
	public function getannounce($request,$respone,$args){
		$postTime=$request->getParam('postTime');
		$user=new UserModel();
		$oper=new OperaModel();
		if($postTime==""){
		   if($user->getannounce()){
		    $data=json_encode($user->getannounce());
		  }else{
		  	$data=array('message'=>'查询失败','code'=>101);
		  }
		 }
		 else{
		    if($oper->announcesearch($postTime)){
		    	$data=json_encode($oper->announcesearch($postTime));
		    }
		 }	
		  return  $respone->withJson($data);
     }
    public function delannounce($request,$respone,$args){
     	$user=new UserModel();
     	$ids=$request->getParam('id');
     	if(is_array($ids)){
     		$id= implode(",",$ids);
     		if($user->delannouns($id)){
     			$data=array('message'=>'用户操作成功','code'=>0);
     		}else{
     			$data=array('message'=>'用户操作失败','code'=>101);
     		}
     	}
     	else{
     		$id=$ids;
     		if($user->delannoun($id)){
     			$data=array('message'=>'用户操作成功','code'=>0);
     		}else{
     			$data=array('message'=>'用户操作失败','code'=>101);
     		}
     	}
     	return $respone->withJSON($data);
     }
    public function getlunbo($request,$respone,$args){
     	$user=new UserModel();
     	$oper=new OperaModel();
     	$listname=$request->getParam('listname');
     	if($listname==""){
     		if($user->getlunbo()){
     		$data=json_encode($user->getlunbo());
     	    }
     	}
     	else{
     		$data=json_encode($oper->getlunbo($listname));
     	}
     	return $data;
     }
    public function getxianshi($request,$respone,$args){
     	$user=new UserModel();
     	$oper=new OperaModel();
     	$listname=$request->getParam('listname');
     	if($listname==""){
     	   if($user->getxianshi()){
     		$data=json_encode($user->getxianshi());
     	   }
     	}else{
     		$data=json_encode($oper->getxianshi($listname));
     	}
     	
     	return $data;
     }
    public function announcemsg($request,$respone,$args){
		$id=$request->getParam('id');
		$user=new OperaModel();
		if($user->announcemsg($id)){
			$ret=json_encode($user->announcemsg($id));
		}
		return $ret;
	}
	public function announceedit($request,$respone,$args){
		$id=$request->getParam('id');
		$announcename=$request->getParam('announcename');
		$announcecontxt=$request->getParam('announcecontxt');
		$type=$request->getParam('type');
		$riqi=$request->getParam('riqi');
		$time=$request->getParam('time');
		$man=$_SESSION['loginName'];
		$opera=new OperaModel();
		if($type=='edit'){
			$ret=json_encode($opera->announceedit($id,$announcename,$announcecontxt));
			if($ret){
			$data=array('massage'=>"编辑成功",'code'=>"$ret");
			}else{
	    	$data=array('message'=>"编辑失败",'code'=>101);
	      }
			return $respone->withJson($data);
		}else if($type=='add'){
			$ret=json_encode($opera->announceadd($announcename,$announcecontxt,$time,$riqi,$man));
			if($ret){
				$data=array('massage'=>"添加成功",'code'=>1);
			}else{
				$data=array('massage'=>"添加失败",'code'=>101);
			}
			 return $respone->withJson($data);
		}
	}
	public function getcustomer($request,$respone,$args){
		$email=$request->getParam('email');
		$user=new UserModel();
		$oper=new OperaModel();
		if($email==""){
			$result=json_encode($user->getcustomer());
        }
        else{
        	$result=json_encode($oper->getcustomer($email));
        }
        return $result;
     }
    public function getemployee($request,$respone,$args){
    	$username=$request->getParam('username');
		$user=new UserModel();
		$oper=new OperaModel();
		if($username==""){
			$result=json_encode($user->getemployee());
        }
        else{
        	$result=json_encode($oper->getemployee($username));
        }
        return $result;
    }
    public function roleList(){
    	$user=new UserModel();
    	if($user->roleList()){
    		$data=json_encode($user->roleList());
    	}
    	return $data;
    }
    public function getSystem($request,$respone,$args){
    	$user=new UserModel();
    	$oper=new OperaModel();
    	$opername=$request->getParam('opername');
    	if($opername==""){
    		$result=json_encode($user->getSystem());
    	}else{
    		$result=json_encode($oper->getSystem($opername));
    	}
    	return $result;
    }
    public function getBusiness($request,$respone,$args){
    	$user=new UserModel();
    	$oper=new OperaModel();
    	$opername=$request->getParam('opername');
    	if($opername==""){
    		$result=json_encode($user->getBusiness());
    	}else{
    		$result=json_encode($oper->getBusiness($opername));
    	}
    	return $result;
    }
    public function customermsg($request,$respone,$args){
    	$oper=new OperaModel();
    	$id=$request->getParam('id');
    	if($oper->customermsg($id)){
    		$data=json_encode($oper->customermsg($id));
    	}else{
    		$data='a';
    	}
    	return $data;
    }
    public function customeredit($request,$respone,$args){
    	$oper=new OperaModel();
    	$id=$request->getParam('id');
    	$username=$request->getParam('username');
    	$email=$request->getParam('email');
    	$phone=$request->getParam('phone');
    	$ret=json_encode($oper->customeredit($id,$username,$email,$phone));
		if($ret){
		  $data=array('massage'=>"编辑成功",'code'=>"$ret");
		}else{
	      $data=array('massage'=>"编辑失败",'code'=>101);
        }
        return $respone->withJson($data);
    }
    public function employeeMsg($request,$respone,$args){
    	$oper=new OperaModel();
    	$id=$request->getParam('id');
    	if($oper->employeeMsg($id)){
    		$data=json_encode($oper->employeeMsg($id));
    	}else{
    		$data='a';
    	}
    	return $data;
    }
    public function roletree($request,$respone,$args){
    	$user=new UserModel();
    	if($user->roletree()){
    		$ret=json_encode($user->roletree());
    		$data=array('data'=>"$ret",'code'=>'0');
    	}else{
    		$data=array('data'=>"查询失败",'code'=>'101');
    	}
    	return $respone->withJson($data);
    }
    public function employedit($request,$respone,$args){
    	$oper=new OperaModel();
    	$id=$request->getParam('id');
    	$username=$request->getParam('username');
    	$realname=$request->getParam('realname');
    	$roleid=$request->getParam('roleid');
    	$phone=$request->getParam('phone');
    	$email=$request->getParam('email');
    	$ret=$oper->employedit($id,$username,$realname,$roleid,$phone,$email);
    	if($ret){
		  $data=array('massage'=>"编辑成功",'code'=>"$ret");
		}else{
	      $data=array('massage'=>"编辑失败",'code'=>101);
        }
        return $respone->withJson($data);
    }
    public function roleget($request,$respone,$args){
    	$user=new UserModel();
    	$rolename=$request->getParam('rolename');
    	if($user->roleget($rolename)){
    		$data=json_encode($user->roleget($rolename));
    	}
    	else{
    		$data='a';
    	}
    	return $data;
    }
    public function employadd($request,$respone,$args){
    	$oper=new OperaModel();
    	$username=$request->getParam('username');
    	$realname=$request->getParam('realname');
    	$roleid=$request->getParam('roleid');
    	$phone=$request->getParam('phone');
    	$email=$request->getParam('email');
    	$ret=$oper->employadd($username,$realname,$roleid,$phone,$email);
    	if($ret){
    		$data=array('massage'=>"添加成功",'code'=>"$ret");
    	}else{
    		$data=array('massage'=>"添加失败",'code'=>"101");
    	}
    	return $respone->withJson($data);
    }
    public function employdel($request,$respone,$args){
     	$oper=new OperaModel();
     	$ids=$request->getParam('id');
     	if(is_array($ids)){
     		$id= implode(",",$ids);
     		if($oper->delemploys($id)){
     			$data=array('message'=>'用户操作成功','code'=>0);
     		}else{
     			$data=array('message'=>'用户操作失败','code'=>101);
     		}
     	}
     	else{
     		$id=$ids;
     		if($oper->delemploy($id)){
     			$data=array('message'=>'用户操作成功','code'=>0);
     		}else{
     			$data=array('message'=>'用户操作失败','code'=>101);
     		}
     	}
     	return $respone->withJSON($data);
     }
     public function rolemsg($request,$respone,$args){
     	$oper=new OperaModel();
     	$id=$request->getParam('id');
     	if($oper->rolemsg($id)){
     		$data=json_encode($oper->rolemsg($id));
     	}else{
     		$data='a';
     	}
     	return "$data";
     }
     public function roleedit($request,$respone,$args){
     	$oper=new OperaModel();
    	$id=$request->getParam('id');
    	$rolecode=$request->getParam('rolecode');
    	$rolename=$request->getParam('rolename');
    	$rolediscript=$request->getParam('rolediscript');
    	$rolelv=$request->getParam('rolelv');
    	$ret=json_encode($oper->roleedit($id,$rolecode,$rolename,$rolediscript,$rolelv));
		if($ret){
		  $data=array('massage'=>"编辑成功",'code'=>"$ret");
		}else{
	      $data=array('massage'=>"编辑失败",'code'=>101);
        }
        return $respone->withJson($data);
     }
     public function roleadd($request,$respone,$args){
     	$oper=new OperaModel();
    	$rolecode=$request->getParam('rolecode');
    	$rolename=$request->getParam('rolename');
    	$rolediscript=$request->getParam('rolediscript');
    	$rolelv=$request->getParam('rolelv');
    	$ret=$oper->roleadd($rolecode,$rolename,$rolediscript,$rolelv);
    	if($ret){
    		$data=array('massage'=>"添加成功",'code'=>"$ret");
    	}else{
    		$data=array('massage'=>"添加失败",'code'=>"101");
    	}
    	return $respone->withJson($data);
     }
    public function getuserrole($request,$respone,$args){
    	$user=new UserModel();
    	$id=$request->getParam('id');
    	if($user->getuserrole($id)){
    		$ret=json_encode($user->getuserrole($id));
    	}else{
    		$ret='a';
    	}
    	return "$ret";
    }
    public function roledelect($request,$respone,$args){
    	$oper=new OperaModel();
    	$id=$request->getParam('id');
    	if($oper->roledelect($id)){
     		$data=array('message'=>'用户操作成功','code'=>0);
    		
    	}else{
     		$data=array('message'=>'用户操作失败','code'=>101);
    	}
    	return $respone->withJson($data);
    }
    public function lunbomsg($request,$respone,$args){
    	$oper=new OperaModel();
    	$id=$request->getParam('id');
    	if($oper->lunbomsg($id)){
    		$data=json_encode($oper->lunbomsg($id));
    	}else{
    		$data='a';
    	}
     	return "$data";
    }
    public function lunboedit($request,$respone,$args){
    	$oper=new OperaModel();
    	$id=$request->getParam('id');
    	$img=$request->getParam('img');
    	$title=$request->getParam('title');
    	$ret=json_encode($oper->lunboedit($id,$img,$title));
		if($ret){
		  $data=array('massage'=>"编辑成功",'code'=>"$ret");
		}else{
	      $data=array('massage'=>"编辑失败",'code'=>101);
        }
        return $respone->withJson($data);
    }
    public function xianshimsg($request,$respone,$args){
    	$oper=new OperaModel();
    	$id=$request->getParam('id');
    	if($oper->xianshimsg($id)){
    		$data=json_encode($oper->xianshimsg($id));
    	}else{
    		$data='a';
    	}
     	return "$data";
    }
    public function xianshiedit($request,$respone,$args){
    	$oper=new OperaModel();
    	$id=$request->getParam('id');
    	$img=$request->getParam('img');
    	$title=$request->getParam('title');
    	$ret=json_encode($oper->xianshiedit($id,$img,$title));
		if($ret){
		  $data=array('massage'=>"编辑成功",'code'=>"$ret");
		}else{
	      $data=array('massage'=>"编辑失败",'code'=>101);
        }
        return $respone->withJson($data);
    }
    public function lunbodel($request,$respone,$args){
    	$oper=new OperaModel();
    	$id=$request->getParam('id');
    	if($oper->lunbodel($id)){
    		$data=array('message'=>'用户操作成功','code'=>0);
    	}else{
     		$data=array('message'=>'用户操作失败','code'=>101);
    	}
    	return $respone->withJson($data);
    }
    public function lunboadd($request,$respone,$args){
    	$oper=new OperaModel();
    	$img=$request->getParam('img');
    	$title=$request->getParam('title');
    	$ret=json_encode($oper->lunboadd($img,$title));
    	if($ret){
    		$data=array('massage'=>"添加成功",'code'=>"$ret");
    	}else{
    		$data=array('massage'=>"添加失败",'code'=>"101");
    	}
    	return $respone->withJson($data);
    }
  }
?>